package org.buptsse.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;

public class HttpHelper {

	//发送post请求
	public static String sendPost(String url,ArrayList<NameValuePair> param) throws ClientProtocolException, IOException
	{
		HttpPost post=new HttpPost(url);
		post.setEntity(new UrlEncodedFormEntity(param, "UTF-8"));
		HttpResponse response=new DefaultHttpClient().execute(post);
		HttpEntity entity=response.getEntity();
		InputStream content=entity.getContent();
		String result=StreamTool.convertStreamToString(content);
		return result;
	}
}
